package EX01;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Set;

public class EX01_SungJukDAO implements EX01_ISungJukDAO {

	private String DRV = "oracle.jdbc.driver.OracleDriver";
	private String URL = "jdbc:oracle:thin:realdance/realdance@112.216.253.125:1521:xe";
	private String insertSQL = "insert into J03Member values (exam.nextval,?,?,?,?,?)";

	@Override
	public boolean insertSungJuk(EX01_SungJukVO s) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		boolean result = false;
		
		try{ 
			conn = this.openDatabase();
			pstmt = conn.prepareStatement(insertSQL);
			pstmt.setInt(1, s.getKor());
			pstmt.setInt(2, s.getEng());
			pstmt.setInt(3, s.getMat());
			pstmt.setInt(4, s.getTot());
			pstmt.setFloat(5, s.getAvg());
			pstmt.setString(6, s.getHakjum());
			pstmt.executeUpdate();
			result = true;
		}catch(Exception ex){
			
		}finally{
			closeDatabase(conn,pstmt,null);
		}
	
		
		return result;
	}



	

		private Connection openDatabase(){
			try{
				Class.forName(DRV);
				return DriverManager.getConnection(URL);
			}catch(Exception ex){
				ex.printStackTrace();
			}return null;
		}
			private void closeDatabase
			(Connection c, PreparedStatement p, ResultSet r){
			
				if(r != null);
				try{r.close(); r = null;}
				catch(Exception e){}
				if(p != null);
				try{p.close(); p = null;}
				catch(Exception e){}
				if(c != null);
				try{c.close(); c = null;}
				catch(Exception e){}
		}
	
}
